//
//  TextViewTableViewCell.m
//  Memo
//
//  Created by A-01 on 2020/7/8.
//  Copyright © 2020 A-01. All rights reserved.
//

#import "TextViewTableViewCell.h"

@interface TextViewTableViewCell () <UITextViewDelegate>


@end

@implementation TextViewTableViewCell


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    
    if ([super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        [self setupUI];
    }
    
    return self;
}


- (void)setupUI{

    self.selectionStyle = UITableViewCellSelectionStyleNone;
    self.backgroundColor = [UIColor clearColor];
    
    UIView * backView = [UIView new];
    
    backView.backgroundColor = ZRWhiteColor;
    
    self.backView = backView;
    
    [self.contentView addSubview:self.backView];
    
    
    UILabel * titleLabel = [UILabel new];
    
    titleLabel.text = @"Wish details";
    titleLabel.textColor = ZRBlackColor;
    titleLabel.font = [UIFont boldSystemFontOfSize:17];
    
    self.titleLabel = titleLabel;
    
    [self.backView addSubview:self.titleLabel];
    
    
    UITextView *textView =[[UITextView alloc]init];
    
    textView.backgroundColor= [UIColor colorWithHexString:@"F1F1F1"];
    textView.text = @"Please enter your wish details";
    textView.font = [UIFont systemFontOfSize:15];
    textView.textColor = [UIColor colorWithHexString:@"666666"];
    textView.delegate = self;
    textView.layer.cornerRadius = 5;
    textView.layer.masksToBounds = YES;
    
    self.textView = textView;
    
    [self.backView addSubview:self.textView];
    
}


-(void)layoutSubviews{
    
    [self.backView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.contentView).offset(20);
        make.trailing.mas_equalTo(self.contentView).offset(-20);
        make.centerY.mas_equalTo(self.contentView);
        make.height.mas_equalTo(200);
    }];
    
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.backView).offset(20);
        make.top.mas_equalTo(self.backView).offset(10);
    }];
    
    [self.textView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.backView).offset(20);
        make.trailing.mas_equalTo(self.backView).offset(-20);
        make.bottom.mas_equalTo(self.backView).offset(-10);
        make.top.mas_equalTo(self.titleLabel.mas_bottom).offset(10);
    }];
}


#pragma mark - UITextViewDelegate
- (void)textViewDidEndEditing:(UITextView *)textView
{
    
    if(textView.text.length < 1){
        textView.text = @"Please enter your wish details";
        textView.textColor = ColorWithRGB(0xbebebe);
    }else{
        
        [textView resignFirstResponder];
    }
}

- (void)textViewDidBeginEditing:(UITextView *)textView
{
    if([textView.text isEqualToString:@"Please enter your wish details"]){
        textView.text=@"";
        textView.textColor=[UIColor blackColor];
    }
}



- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
